package ttc.mBackup.BackupAndRestoreSMS;

import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class SMSList extends Activity {
	private SMSClass smsClass;
	private SMSQuery smsQuery;
	private String m_id;
	private String m_body;
	private String m_address;
	private ArrayList<SMSClassCustomViewGroup> arraySMSClassCustomViewGroup;
	SMSListArrayAdapter smsArrayAdapter;
	private ListView lstView;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		smsQuery=new SMSQuery(getApplicationContext());
		setContentView(R.layout.layout_list_sms);
		arraySMSClassCustomViewGroup= new ArrayList<SMSClassCustomViewGroup>();
		
		Cursor cursorsmsquery=smsQuery.getAllSMS();
		cursorsmsquery.moveToFirst();
		do
		{
			 m_id= cursorsmsquery.getString(cursorsmsquery.getColumnIndex("_id"));
			 m_body=cursorsmsquery.getString(cursorsmsquery.getColumnIndex("body"));
			 m_address=cursorsmsquery.getString(cursorsmsquery.getColumnIndex("address"));
			 SMSClassCustomViewGroup smsClassCustomViewGroup= new SMSClassCustomViewGroup(m_body, m_address, m_id, false);
			 arraySMSClassCustomViewGroup.add(0,smsClassCustomViewGroup);
			 
			 cursorsmsquery.moveToNext();
		}while(!cursorsmsquery.isLast());
		smsArrayAdapter= new SMSListArrayAdapter(this, R.layout.layout_list_sms	, arraySMSClassCustomViewGroup);
		
		lstView= (ListView) findViewById(R.id.listSMS);
		lstView.setTextFilterEnabled(true);
		lstView.setAdapter(smsArrayAdapter);
		//Log.i("I","begin");
		//setContentView(R.layout.layout_list_sms);
		//Log.i("I","end setcontentView");
		//lstView=(ListView)findViewById(R.id.listSMS);
		//Cursor cursorsmsquery=smsQuery.getAllSMS();
		//Log.i("I","end Query");
		//arraySMS=smsQuery.getInboxSMS();
		//Log.i("Tag",Integer.toString(cursorsmsquery.getCount()));
		//startManagingCursor(cursorsmsquery);
		//ListAdapter lstAdapter= new SimpleCursorAdapter(this, R.layout.row_sms, cursorsmsquery, new String[]{"address","body"}, new int[]{R.id.txtContactPhone,R.id.txtSMSBody});
		//SimpleCursorAdapter lstAdapter= new SimpleCursorAdapter()
		//setListAdapter(new ArrayAdapter<SMSClass>(this, R.layout.layout_list_sms,));
		//setListAdapter(new ArrayAdapter<SMSClass>(this,R.layout.layout_list_sms,arraySMS));
		//lstView.setAdapter(smsArrayAdapter);
		
	}
	
	protected void onListItemClick(ListView l, View v,int position, long id)
	{
		//l.set
		SMSClass sms= new SMSClass();
		sms.address="iii";
	}
	public void onItemSelected(AdapterView<?> parent, View v, int position, long id) 
	{
		SMSClass sms= new SMSClass();
		sms.address="iii";
	}

}
